$(function(){
	$('.showmap').on('click',function(){
		var that=this
		popup(this)
		var map = new AMap.Map('showlocation', {
			resizeEnable: true,
			zoom: 11,
			center: [118.57, 24.82]
		});
		var driverlocload = layer.load(0, {
			shade:  [0.3,'#fff']
		});
		AMapUI.loadUI(['overlay/SimpleMarker'], function(SimpleMarker) {
		$.ajax({
			type: 'post',
			url: '{:url("admin/beidou/cars")}',
			data: {
				number: encodeURI($(that).closest('tr').data('number'))
			},
			success: function(res) {
				console.log(res)
					layer.close(driverlocload);
					console.log(res)
					if(res.code == 1) {
						if(res.data[0]) {
							if(res.data[0].loc) {
								if(res.data[0].loc[0]) {
									carloc = res.data[0].loc
									driverloc = new SimpleMarker({
										//普通文本
										iconStyle: {
											src: '{$static_dir}/assets/img/car.png',
											style: {
												width: '15px',
												height: '30px'
											}
										},
										position: carloc,
										cont: {}
									});
									console.log('放入地图')
									driverloc.setMap(map);
								} else {
									Err('暂无定位')
								}
							} else {
								Err('暂无定位')
							}
						} else {
							Err('暂无定位')
						}
					} else {
						Err('暂无定位')
					}
			}
		});
		
		
			
		});
	});
	//删除
	$('.delete-list').on('click',function(){
		console.log(1)
		popup(this,"{:url('delete')}");
		
	});
	//启用
	$('.startusing').on('click',function(){
		popup(this,"{:url('state')}");
		
	});
	//禁用
	$('.forbidden').on('click',function(){
		popup(this,"{:url('state')}");
		
	});
	//全选
	$('.check-all').on('click',function(){
		checkall(this)
	});
	$('.check-list').on('click',function(){
		checkall(this)
	});
	//删除多个
	$(".delete-multiple").on('click',function(){
		popup(this,"{:url('delete')}");
	});
	//查看订单弹窗
    $(".look_order").on('click', function() {
        choosecar("/admin/order/lookOrder?op=search&driver_id="+$(this).data('id'))
    });
    //查看位置弹窗
    $(".look_where").on('click', function() {
        choosecar("/admin/beidou/lookWhere?op=search&driver_id="+$(this).data('id'))
    });
//	$('.unbind').on('click', function() {
//		$('.driver_id').val($(this).closest('tr').data('id'))
//		choosecar("{:url('car/index',['op'=>'unbind'])}?driver_id="+$(this).closest('tr').data('id'))
//	});
//	$('.bind').on('click', function() {
//		$('.driver_id').val($(this).closest('tr').data('id'));
//		var id = $(this).closest('tr').data('id');
//		choosecar("{:url('car/index',['op'=>'bind'])}?driver_id="+$(this).closest('tr').data('id'));
//	});
	$('.bind').on('click', function() {
		choosecar("{:url('car/relevance',['op'=>'unbind'])}?driver_id="+$(this).closest('tr').data('id'))
	});
	$('.choose').on('click', function() {
		var index = parent.layer.getFrameIndex(window.name);
		parent.$('.driver').val($(this).data('name'));
		parent.$('.driver_id').val($(this).data('id'));
		parent.layer.close(index);

	});
	$('.company_name').on('click', function() {
		choosecar("{:url('company/index',['op'=>'search'])}")
	});
})
